#include "stdafx.h"
#include "WinRate.h"

using namespace ExperientialSystem;

WinRate::WinRate() :_winrate(DEFAULT_WINRATE)
{
}

WinRate::WinRate(const double winrate) :_winrate(winrate)
{

}

WinRate::~WinRate()
{
}

void WinRate::Update(const IValue* value)
{
	const WinRate *derive = dynamic_cast<const WinRate*>(value);
	if (NULL != derive)
	{
		this->_winrate = derive->_winrate;
	}
}

int WinRate::Compare(const IValue* value)
{
	const WinRate *derive = dynamic_cast<const WinRate*>(value);
	if (NULL != derive)
	{
		return this->_winrate == derive->_winrate ? 0 : this->_winrate > derive->_winrate ? 1 : -1;
	}
	else
	{
		throw invalid_argument("Invalid type.");
	}
}

IValue* WinRate::Clone() const
{
	WinRate* copy = new WinRate(_winrate);
	return copy;
}

void WinRate::Write(ofstream& out) const
{
	out << _winrate;
}

void WinRate::Read(ifstream& in)
{
	in >> _winrate;
	if (_winrate == 0.0)
	{
		_winrate = DEFAULT_WINRATE;
	}
}
